# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=vala
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.54.2
pkgrel=1
pkgdesc="Compiler for the GObject type system (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://wiki.gnome.org/Projects/Vala"
license=("LGPL")
makedepends=("help2man"
             "${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
              $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-aarch64* ]] || \
              echo "${MINGW_PACKAGE_PREFIX}-vala")) # Remove this workaround after vala available
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
          $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-aarch64* ]] || \
            echo "${MINGW_PACKAGE_PREFIX}-graphviz")) # Remove this workaround afer graphviz available
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz)
sha256sums=('884de745317d4d56e4e8cede993dc8f04d50cfca36cf60d2f2f278c30c2b1311')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  autoreconf -ivf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-aarch64* ]] && \
      echo "--disable-valadoc" || true) # Remove this workaround afer graphviz available

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  # Move libvalaccodegen.dll to correct directory
  mv "${pkgdir}${MINGW_PREFIX}"/lib/bin/libvalaccodegen.dll "${pkgdir}${MINGW_PREFIX}"/bin/libvalaccodegen.dll
  rm -rf "${pkgdir}${MINGW_PREFIX}"/lib/bin

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
